<template>
  <!-- 没有图片 -->
  <van-cell v-if="type === 0" :title="aritcleInfo.title" :label="label" />

  <!-- 一张图片 -->
  <van-cell v-else-if="type === 1" :title="aritcleInfo.title" :label="label">
    <van-image width="100" height="100" :src="aritcleInfo.cover?.images[0]" />
  </van-cell>

  <!-- 三张图片 -->
  <van-cell v-else :title="aritcleInfo.title">
    <template #label>
      <!-- 三张图片 -->
      <van-image
        v-for="(item, index) in aritcleInfo.cover?.images"
        :key="index"
        width="100"
        height="100"
        :src="item"
      />
      <!-- 文本 -->
      <span> {{ label }} </span>
    </template>
  </van-cell>
</template>

<script>
import dayjs from '@/utils/dayjs'

export default {
  props: {
    // 默认值: 如果是基本数据类型直接给
    // 复杂数据类型, 以函数的返回值给他
    aritcleInfo: {
      type: Object,
      default: () => ({})
    }
  },
  computed: {
    type() {
      return this.aritcleInfo.cover?.type
    },
    label() {
      // dayjs(时间).fromNow()
      const { aut_name, pubdate, comm_count } = this.aritcleInfo
      return `${aut_name} ${comm_count}评论 ${dayjs(pubdate).fromNow()}`
    }
  }
}
</script>

<style></style>
